import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.table.AbstractTableModel;



public class Professor {

	public static JButton ShowCorses		=new JButton( "Show Corses" );
	public static JButton SubmitGrade		=new JButton(	"Submit Grade" );
	public static JButton PII				=new JButton( "Personal Information");
	public static JButton CourseLog			=new JButton( "Course Log" );
	public static JButton Logout			=new JButton( "Log out" );
	public static JButton EditbPII 			=new JButton( "Edit Personal Information");
	public static JComboBox ProfCoursList	= new JComboBox();
	public static JComboBox ProfCoursList2	= new JComboBox();
	public static JTextField assignedAccountID     = new JTextField("");
    public static JButton    ProfAssign			= new JButton("Assign TA");
    public static String[][] Courses;
    int NumberOfRows,NumberOfColumns;
	Object[][] MyArray=null;
	private javax.swing.JScrollPane jScrollPane2;
	private javax.swing.JTextArea ActionTextArea;
	public static JTable DataBaseTable = new JTable();
	public static JTable proflogtable = new JTable();
	public boolean check=false;
	JTextField usernametxt;
	JLabel statuslbl;
	public static JButton submitbtn; 
	public static String[][] CurrentStudentList;
	public static String[][] logdetails;
	
	public static JComboBox gradecombo		= new JComboBox();
	public static String[][] professorcourses;
	public static JPanel J ;
	 String[][] proflog=null;
	Professor(){
	}
	public JPanel SMenueInterface( )
		{
			 JPanel SMenueInterface			 = new JPanel( );
			 SMenueInterface.setLayout(	new GridLayout( 8 , 1 ) );
			 SMenueInterface.add( ShowCorses );
			 SMenueInterface.add( PII );
			 SMenueInterface.add(CourseLog);
			 SMenueInterface.add( Logout );
			 return( SMenueInterface );
		}
		
		
		public JPanel getaction(String line)
		{
			String[] Line=line.split(";");
			JPanel J=new JPanel();
			if (Line[0].equals("courses"))
			return(getmy_course(Line,2));
			else if (Line[0].equals("my_info"))
				return(PII(line));
			else if (Line[0].equals("Students"))
				return(Studenttabel(line));
			else if (Line[0].equals("courselog"))
			{	int l=0;
			int NumberOfRows=(Line.length-1)/7;
				//String[][] line2=new String[Line.length-1][8];
				logdetails=new String[0][7];
				if (!Line[1].equals("null"))
				{
						
						logdetails=new String[NumberOfRows][7];
						logdetails[0][0]=Line[1];
						logdetails[0][1]=Line[2];
						logdetails[0][2]=Line[3];
						logdetails[0][3]=Line[4];
						logdetails[0][4]=Line[5];
						logdetails[0][5]=Line[6];
						logdetails[0][6]=Line[7];
						int k=8;
						for (int o=1;o<NumberOfRows;o++)
						{
							for (int i=0;i<7;i++)
							{
								logdetails[o][i]=Line[i+k];
							}
							k+=7;
						}
				
				}
				
				return(logtabel(logdetails));
			}
			else
				return(logtabel(logdetails));
				//return J;
		}
		
		public JPanel PII(String Pinfo)
		{
			JPanel PII	=new JPanel();
	      	PII.setLayout( new GridLayout( 10 , 5 ) );
	      	
	      	//ResultSet rs = statement.executeQuery("select * from AccountInfo1 where PersonalId ='5'");
	      	//while (rs.next()) {
	      	String[]    pii           = Pinfo.split(";");
	      	JTextField	Userfullname  = new JTextField(pii[2]);
	      	JTextField	Useremail     = new JTextField(pii[1]);
	      	JTextField	Userphone     = new JTextField(pii[4]);
	      	JTextField	Useraddress   = new JTextField(pii[3]);
			JTextField	PasswordText  = new JTextField("");
			JLabel Useremaillb   = 	new JLabel("Email",10);
			JLabel namelb    = 		new JLabel("Name ");
			JLabel Useraddresslb = new JLabel("Address");
			JLabel Userphonelb   = new JLabel("Phone");
			JLabel PasswordLabel = new JLabel("Password");	
			
			
			PII.add(Useremaillb);
			PII.add(Useremail);
			PII.add(namelb);
			PII.add(Userfullname);
			PII.add(Useraddresslb);
			PII.add(Useraddress);
			PII.add(Userphonelb);
			PII.add(Userphone);	
			//PII.add(PasswordLabel);
			//PII.add(PasswordText);
			PII.add(EditbPII);
			return(PII);
		}
		public JPanel getmy_course(String[] a,int start){
			 JPanel Prof=new JPanel();
			 ProfCoursList= new JComboBox();
			 
			 ProfCoursList2=new JComboBox();
			 Prof.setLayout(new GridLayout((a.length/2),2));
			 for(int i=start+1;i<a.length;i++)
			 {
			 ProfCoursList.addItem(a[i]);
			 ProfCoursList2.addItem(a[i]);
			 }
			 //ProfCoursList= new JComboBox(a);
			 Prof.add(ProfCoursList);
			 return(Prof);
	   }
		
		
		
		public JPanel Studenttabel(String line) 
		{	J=new JPanel( );
			
			String[] StudentList= line.split(";");
//			String [] AttributeNames;
//			String state;
			
			javax.swing.JScrollPane jScrollPane1;
			NumberOfRows=(StudentList.length-1)/5;
			NumberOfColumns=2;
			JLabel label;
			JLabel usernamelbl;
			JLabel gradelbl;
			MyArray=new Object[NumberOfRows][NumberOfColumns];
			int l=1;
			if (!StudentList[1].equals("null"))
			{
					MyArray[0][0]=StudentList[1];
					MyArray[0][1]=StudentList[2];
					for(int R=1;R<=NumberOfRows-1;R++)
					{l+=5;
								MyArray[R][0] = StudentList[l+3];
								MyArray[R][1] = StudentList[l+1];
					}
					CurrentStudentList=new String[NumberOfRows][5];
					CurrentStudentList[0][0]=StudentList[1];
					CurrentStudentList[0][1]=StudentList[2];
					CurrentStudentList[0][2]=StudentList[3];
					CurrentStudentList[0][3]=StudentList[4];
					CurrentStudentList[0][4]=StudentList[5];
					int k=6;
					for (int o=1;o<NumberOfRows;o++)
					{
						for (int i=0;i<5;i++)
						{
							CurrentStudentList[o][i]=StudentList[i+k];
						}
						k+=5;
					}
			
			}
			J.add(jScrollPane1 = new javax.swing.JScrollPane());
			J.add(DataBaseTable);
			
			J.add(label = new JLabel(":::Please Select a Course Number:::"));
			J.add(ProfCoursList);
			J.add(usernamelbl = new JLabel());
			J.add(usernametxt = new JTextField());
			J.add(gradelbl = new JLabel());
			J.add(submitbtn = new JButton());
			J.add(statuslbl = new JLabel());
			
			J.add(gradecombo); 
			J.setLayout(null);
			
			J.add(label);
			label.setBounds(10,10,250,50);
			ProfCoursList.setBounds(10, 45, 190, 50);
			
			J.add(usernamelbl);
			usernamelbl.setText("Student name");
			usernamelbl.setBounds(10,280,200,30);
			J.add(usernametxt);
			usernametxt.setEditable(false);
			usernametxt.setBounds(100,280,200,30);
			J.add(gradelbl);
			gradelbl.setText("Grade");
			gradelbl.setBounds(10,310,200,30);
			J.add(gradecombo);
			gradecombo.setBounds(100,310,200,30);
		
			J.add(submitbtn);
			submitbtn.setText("Submit/Update Grade");
			submitbtn.setBounds(100,340,200,60);
			
			J.add(statuslbl);
			statuslbl.setText("");
			statuslbl.setBounds(100,400,300,30);
			DataBaseTable.setModel(new javax.swing.table.DefaultTableModel(
			new Object [][] { {null},{null},{null},{null}},new String [] { ""}) 
			
			{
			Class[] types = new Class [] { java.lang.Object.class};
			boolean[]canEdit=new boolean[]{false};
			
			public Class getColumnClass(int columnIndex) {
			return types [columnIndex];
			}
			
			public boolean isCellEditable(int rowIndex, int columnIndex) {
			return canEdit [columnIndex];
			}
			});
			
			DataBaseTable.setModel(new MyTableModel());
			DataBaseTable.setVisible(true);
				
			jScrollPane1.setViewportView(DataBaseTable);
			
			J.add(jScrollPane1);
			jScrollPane1.setBounds(3, 120, 460, 150);
			
			J.revalidate();
			return(J);
			}
		
			public void DataBaseTableMouseReleasedStudenttabel() {
			usernametxt.setText(new MyTableModel().getValueAt(DataBaseTable.getSelectedRow(),0).toString());
			statuslbl.setText("");
			statuslbl.setBackground(null);
			}
			public JPanel seeStudenttabel () {
				JPanel j=new JPanel();
				j.setLayout(new GridLayout(0,2));
				JLabel ActivityType=new JLabel("Student Name:");
				j.add(ActivityType);
				JLabel ActivityTypelb=new JLabel(CurrentStudentList[DataBaseTable.getSelectedRow()][3]);
				j.add(ActivityTypelb);
			
				JLabel SubjectName=new JLabel("Student Email:");
				j.add(SubjectName);
				JLabel SubjectNamelb=new JLabel(CurrentStudentList[DataBaseTable.getSelectedRow()][2]);
				j.add(SubjectNamelb);
				
				JLabel ActivityPriorty=new JLabel("User Name:");
				j.add(ActivityPriorty);
				JLabel ActivityPriortylb=new JLabel(CurrentStudentList[DataBaseTable.getSelectedRow()][0]);
				j.add(ActivityPriortylb);
				
				JLabel ActivityValue=new JLabel("Grade :");
				j.add(ActivityValue);
				JTextArea ActivityValuelb=new JTextArea(CurrentStudentList[DataBaseTable.getSelectedRow()][1]);
				jScrollPane2 = new javax.swing.JScrollPane(ActivityValuelb);
				ActivityValuelb.setEditable(false);
				j.add(jScrollPane2);
				
//				JPanel j=new JPanel();
//				JLabel lb=new JLabel(new MyTableModel().getValueAt(DataBaseTable.getSelectedRow(),0).toString());
//				j.add(lb);
//				JLabel email=new JLabel(CurrentStudentList[DataBaseTable.getSelectedRow()][0]);
//				j.add(email);
//				JLabel e2=new JLabel(CurrentStudentList[DataBaseTable.getSelectedRow()][1]);
//				j.add(e2);
//				JLabel e3=new JLabel(CurrentStudentList[DataBaseTable.getSelectedRow()][3]);
//				j.add(e3);
//				JLabel e4=new JLabel(CurrentStudentList[DataBaseTable.getSelectedRow()][4]);
//				j.add(e4);
				return(j);
				
				
				}

			class MyTableModel extends AbstractTableModel {
			//You can choose any long value for serialVersionUID.
			//I chose 317 because this is CSCI 317.
			String[] s={"Name","Grade"};
			private static final long serialVersionUID=317L;
			public int getColumnCount() {
			return (NumberOfColumns);
			}
			public int getRowCount() {
			return(NumberOfRows);
			}
			public String getColumnName(int i) {
			return (s[i]);
			}
			public java.lang.Object getValueAt(int row, int column) {
			return(MyArray[row][column]);
			}
			public Class getColumnClass(int c) {
			return getValueAt(0, c).getClass();
			}
			public boolean isCellEditable(int row, int col) {
			if (col < 3) { 
			return false;
			} else {
			return true;
			}
			}
			public void setValueAt(Object value, int row, int col) {
			MyArray[row][col] = value;
			fireTableCellUpdated(row, col);
			}        
			}

			
			public void addcourses(){
				int count=ProfCoursList.getItemCount();
				String grade[] = {"A","A-","B+","B","B-","C+","C","C-","F"};
				for (int i=0;i<grade.length;i++)
				{
					gradecombo.addItem(grade[i]);
				}
				
				gradecombo.setSelectedIndex(0);
				
				String[] cousetemp=new String[Courses.length];
				int l=0;
				if(ProfCoursList.getItemCount()<Courses.length)
				{
					for(int i=0;i<Courses.length;i++){
						
						if(Courses[i][1].equals("Professor")){
							cousetemp[l]=Courses[i][2];
							l++;
						}
							
					}
				}
				String[] temps=new String[l];
					for (int i=0;i<l;i++)
					{
						temps[i]=cousetemp[i];
					}
				professorcourses=new String [l][2];
				if(count<Courses.length)
				{
					int k=0;
					for(int i=0;i<Courses.length;i++){
						
						if(Courses[i][1].equals("Professor")){
							professorcourses[k][0]=Courses[i][0];
							professorcourses[k][1]=Courses[i][2];
							k++;
							
						}
							
					}
				}
				ProfCoursList=new JComboBox(temps);
				ProfCoursList2=new JComboBox(temps);
			}
			
			 public JPanel logtabel(String [][] table) 
				{	
				 	
				 	J=new JPanel( );
					
				
					//String[] StudentList= line.split(";");
					String [] AttributeNames;
					String state;
					
					javax.swing.JScrollPane jScrollPane1;
					NumberOfRows=table.length;
					NumberOfColumns=2;
					JLabel label;
					
					MyArray=new Object[NumberOfRows][NumberOfColumns];
					proflog=new String[NumberOfRows][7];

					int l=1;
					
							for(int R=0;R<table.length;R++)
							{
										for(int i=0;i<7;i++)
										{
											proflog[R][i] = table[R][i];
										}
							}
					for(int R=0;R<table.length;R++)
						{
						MyArray[R][0] = proflog[R][3];
						MyArray[R][1] = proflog[R][4];
						}
					J.add(label = new JLabel(":::Please Select a Course Number:::"));
					J.add(ProfCoursList2);
					
					J.add(jScrollPane1 = new javax.swing.JScrollPane());
					J.add(proflogtable);

					ProfCoursList2.setBounds(10, 45, 190, 50);

					J.setLayout(null);
					

					
					proflogtable.setModel(new javax.swing.table.DefaultTableModel(
					new Object [][] { {null},{null},{null},{null}},new String [] { ""}) 
					
					{
					Class[] types = new Class [] { java.lang.Object.class};
					boolean[]canEdit=new boolean[]{false};
					
					public Class getColumnClass(int columnIndex) {
					return types [columnIndex];
					}
					
					public boolean isCellEditable(int rowIndex, int columnIndex) {
					return canEdit [columnIndex];
					}
					});
					
					proflogtable.setModel(new MyTableModel2());
					proflogtable.setVisible(true);
						
					jScrollPane1.setViewportView(proflogtable);
					
					J.add(jScrollPane1);
					jScrollPane1.setBounds(3, 120, 550, 150);
					
					J.revalidate();
					return(J);
					}	
				
					public void DataBaseTableMouseReleasedlogtabel() {
//					usernametxt.setText(new MyTableModel().getValueAt(DataBaseTable.getSelectedRow(),0).toString());
//					statuslbl.setText("");
//					statuslbl.setBackground(null);
					}
					public JPanel seelogtabel () {
						JPanel j=new JPanel();
						j.setLayout(new GridLayout(0,2));
						JLabel ActivityType=new JLabel("Activity Type:");
						j.add(ActivityType);
						JLabel ActivityTypelb=new JLabel(proflog[proflogtable.getSelectedRow()][3]);
						j.add(ActivityTypelb);
						JLabel ActivityTime=new JLabel("Activity Time:");
						j.add(ActivityTime);
						JLabel ActivityTimelb=new JLabel(proflog[proflogtable.getSelectedRow()][0]);
						j.add(ActivityTimelb);
						
						JLabel SubjectName=new JLabel("Done by:");
						j.add(SubjectName);
						JLabel SubjectNamelb=new JLabel(proflog[proflogtable.getSelectedRow()][2]);
						j.add(SubjectNamelb);
						
						JLabel ActivityPriorty=new JLabel("The Action:");
						j.add(ActivityPriorty);
						JLabel ActivityPriortylb=new JLabel(proflog[proflogtable.getSelectedRow()][6]);
						j.add(ActivityPriortylb);
						
						JLabel ActivityValue=new JLabel("Activity Value:");
						j.add(ActivityValue);
						JTextArea ActivityValuelb=new JTextArea(proflog[proflogtable.getSelectedRow()][5]);
						jScrollPane2 = new javax.swing.JScrollPane(ActivityValuelb);
						ActivityValuelb.setEditable(false);
						j.add(jScrollPane2);
//						JLabel ActivityDesc=new JLabel("Activity Description:");
//						j.add(ActivityDesc);
//						JLabel ActivityDesclb=new JLabel(proflog[proflogtable.getSelectedRow()][2]);
//						j.add(ActivityDesclb);
						
						
						
//						JLabel ActivityType=new JLabel("Activity Type:");
//						j.add(ActivityType);
//						JLabel email=new JLabel(adminlog[DataBaseTable.getSelectedRow()][0]);
//						j.add(email);
//						JLabel e2=new JLabel(adminlog[DataBaseTable.getSelectedRow()][1]);
//						j.add(e2);
//						JLabel e3=new JLabel(adminlog[DataBaseTable.getSelectedRow()][2]);
//						j.add(e3);
//						JLabel e4=new JLabel(adminlog[DataBaseTable.getSelectedRow()][3]);
//						j.add(e4);
						return(j);
						
						
						}

					class MyTableModel2 extends AbstractTableModel {
					//You can choose any long value for serialVersionUID.
					//I chose 317 because this is CSCI 317.
					String[] s={"ActivityType","ActivityPriorty"};
					private static final long serialVersionUID=317L;
					public int getColumnCount() {
					return (NumberOfColumns);
					}
					public int getRowCount() {
					return(NumberOfRows);
					}
					public String getColumnName(int i) {
					return (s[i]);
					}
					public java.lang.Object getValueAt(int row, int column) {
					return(MyArray[row][column]);
					}
					public Class getColumnClass(int c) {
					return getValueAt(0, c).getClass();
					}
					public boolean isCellEditable(int row, int col) {
					if (col < 7) { 
					return false;
					} else {
					return true;
					}
					}
					public void setValueAt(Object value, int row, int col) {
					MyArray[row][col] = value;
					fireTableCellUpdated(row, col);
					}        
					}
	
}
